

//页内跳转
function redirectLocal(url){
	
	var jqContent = $("#tf-data-content");
	
	if(jqContent.length == 0){
		jqContent = $(parent.document).find("#tf-data-content");
	}
	
	jqContent.attr("src" , url);
}


//阿里云上传附件
function alyUploadAttachment(fileInputId , callback){
	 $.ajaxFileUpload({
         url: parent.LocalCache.currentHost + "/main/uploadAttachment",
         type :'POST',
         fileElementId : fileInputId,
         dataType: "json",
         async : true,   //是否是异步
         success: function (data) {
        	 callback(data);
         }
     });
}


//ajax同步请求调用
function ajaxRequest(requestUrl , params){
	var result;
	$.ajax({
		url : requestUrl ,
		type :'POST',
		data : params ,
		dataType : "json",
		async : false,
		contentType : 'application/x-www-form-urlencoded; charset=UTF-8',
		success:function(data){
			result = data;
		}		
	});
	return result;
}

//根据类型获取配置表
function getSysConfigByType(type){
	var params = {offset : 0 , pageSize : 1};
	params.type = type;
	var data = ajaxRequest(parent.LocalCache.currentHost  + "/sysConfig/findSysConfigList" , params);
	return data.success ? data.data[0] : undefined;
}

/**
 * 获取配置表定义的枚举信息
 */
function getEnumInfo(type){
	
	var data = getSysConfigByType(type);
	
	if(!data ||  !data.configJson || data.configJson == "")
		return undefined;
		
	var config = JSON.parse(data.configJson);
	
	var enumInfo = {};
	
	var optionTxt = "";
	
	var enumMap = {};
	for(var i = 0 ; config && i < config.length ; i ++){
		var item = config[i];
		optionTxt += '<option value="'+item.serialNumber+'">'+item.typeName+'</option>';
		enumMap[item.serialNumber] = item.typeName;
	}
	
	enumInfo.noAllOptionTxt = optionTxt;
	enumInfo.optionTxt = '<option value="">'+type+'</option>' + optionTxt;
	enumInfo.enumMap = enumMap;
	
	return enumInfo;
	
}

/**
 * 初始化下拉列表,返回enumMap : key : serialNumber , value : typeName
 * isRemoveAllOption : true 没有全部的option 
 * excludeClass : 当dom元素含有excludeClass所表示的class,则必须有全部option
 */
function initSelectList(type , jqElement , isRemoveAllOption , excludeClass){
	
	var enumInfo = getEnumInfo(type);
	
	if(!enumInfo) return;
	
	/*根据情况初始化*/
	for(var i = 0 ; jqElement && i < jqElement.length ; i ++){
		var jqItem = $(jqElement[i]);
		var optionTxt = isRemoveAllOption && ( !excludeClass || !jqItem.hasClass(excludeClass)) ? enumInfo.noAllOptionTxt : enumInfo.optionTxt;
		jqItem.html(optionTxt);
	}
	
	return enumInfo;
}
